package com.webmarmun.news;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

public class NewsActivity extends Activity {
	ImageView img;
	int totalviews;
    View view[];
    ImageView newsview[];

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final LayoutInflater  inflater =     (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        
       LinearLayout insertIt = (LinearLayout) findViewById(R.id.horisontalcontainer);
        boolean loadView = false;
		View v = null; 
		boolean firstLoad = true;
		List dataList = new ArrayList();
		
		addDatatoList(dataList);
		view = new View[dataList.size()];
		newsview = new ImageView[dataList.size()];
		
		for(int i=0; i<dataList.size(); i++) {
			
				DataDTO mdto = (DataDTO) dataList.get(i);
				
				 ViewHolder vi = new ViewHolder(this);
				
				view[i] = inflater.inflate(R.layout.imageslist,null);
				newsview[i]= (ImageView)view[i].findViewById(R.id.oneimage);
				newsview[i].setPadding(5,5,5,5);
				final String text=mdto.getName().toString();
				newsview[i].setOnClickListener(new OnClickListener() {
		            @Override
		            public void onClick(View v) {
		                
		                Toast.makeText(v.getContext(),text,Toast.LENGTH_SHORT).show();
		            }
		        });

			
				
				String imageUrl = mdto.getImageURL();
				 if (imageUrl != null)
		 	    	{
					    LazyLoadImage downloader = new LazyLoadImage(newsview[i]);
			 			downloader.execute(imageUrl);	
		 			}
				 
				// vi.v = newsview[i];
				 insertIt.addView(view[i]);
				
				 
			
		
		
		}
		
		
		
    }
    
    
    @SuppressWarnings("unchecked")
	private void addDatatoList(@SuppressWarnings("rawtypes") List dataList){
		DataDTO dataDTO1 = new DataDTO();
		dataDTO1.setName("First Tab");
		dataDTO1.setImageURL("http://prvisud.rs/slike/seminarparnica_thumb.jpg");
		dataList.add(dataDTO1);
		
		DataDTO dataDTO2 = new DataDTO();
		dataDTO2.setName("Second Tab");
		dataDTO2.setImageURL("http://prvisud.rs/slike/okr_prez_thumb.jpg");
		dataList.add(dataDTO2);

		DataDTO dataDTO3 = new DataDTO();
		dataDTO3.setName("Third Tab");
		dataDTO3.setImageURL("http://prvisud.rs/slike/invalidi_thumb.jpg");
		dataList.add(dataDTO3);
		
		DataDTO dataDTO4 = new DataDTO();
		dataDTO4.setName("Fourth Tab");
		dataDTO4.setImageURL("http://prvisud.rs/slike/novesudije1_thumb.jpg");
		dataList.add(dataDTO4);
		
		DataDTO dataDTO5 = new DataDTO();
		dataDTO5.setName("Fifth Tab");
		dataDTO5.setImageURL("http://prvisud.rs/slike/folders.jpg");
		dataList.add(dataDTO5);
		
		DataDTO dataDTO6 = new DataDTO();
		dataDTO6.setName("Sixth Tab");
		dataDTO6.setImageURL("http://prvisud.rs/slike/fruskagora.jpg");
		dataList.add(dataDTO6);
		
		DataDTO dataDTO7 = new DataDTO();
		dataDTO7.setName("Seventh Tab");
		dataDTO7.setImageURL("http://prvisud.rs/slike/pravni.jpg");
		dataList.add(dataDTO7);
		
		DataDTO dataDTO8 = new DataDTO();
		dataDTO8.setName("Eigth Tab");
		dataDTO8.setImageURL("http://prvisud.rs/slike/LogoSud.jpg");
		dataList.add(dataDTO8);
	}
    
    static class ViewHolder extends LinearLayout{
        
        
        public ViewHolder(Context context) {
            super(context);
        }
        public ImageView v;
      
    }

}